﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;
using YArchitech.Revit;

namespace YArchitech.HVAC.AuxiliaryCurve
{
	public class RoomOrSpaceSelction : AuxiliarySelection
	{
		public RoomOrSpaceSelction(ExternalCommandData cmd)
		{
			this.m_cmd = cmd;
			this.sel = this.m_cmd.Application.ActiveUIDocument.Selection;
		}

		public override bool Select()
		{
			Document document = this.m_cmd.Application.ActiveUIDocument.Document;
			ISelectionFilter selectionFilter = new RoomAndSpaceSelectionFilter();
			Reference reference = this.sel.PickObject((Autodesk.Revit.UI.Selection.ObjectType)1, selectionFilter, "请选择房间");
			Element element = document.GetElement(reference);
			if (element.GetType() != typeof(Room) && element.GetType() != typeof(Space))
			{
				YJKMessageBox.Information("所选择的不是房间或空间，请重新选择!");
				return false;
			}
			SpatialElement spatialElement = element as SpatialElement;
			new SpatialElementBoundaryOptions().SpatialElementBoundaryLocation = 0;
			BoundingBoxXYZ boundingBox;
			if (spatialElement.GetType() == typeof(Room))
			{
				boundingBox = (spatialElement as Room).ClosedShell.GetBoundingBox();
			}
			else
			{
				boundingBox = (spatialElement as Space).ClosedShell.GetBoundingBox();
			}
			base.Min = boundingBox.Min;
			base.Max = boundingBox.Max;
			return true;
		}
	}
}
